package com.weather.pm.fragments;

import java.util.ArrayList;

import com.weather.pm.R;
import com.weather.pm.adapter.OrderCPIAdapter;
import com.weather.pm.beans.OrderCPI;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class OrderFragment extends Fragment implements OnClickListener{

	private LinearLayout mFragmentLayout;
	private RelativeLayout mAirPart;
	private RelativeLayout mPm25Part;
	private RelativeLayout mAirFragment;
	private RelativeLayout mPmFragment;
	private TextView mAirText;
	private TextView mPmText;
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mFragmentLayout = (LinearLayout)inflater.inflate(R.layout.order_fragment, null);
		initView();
		initListener();
		return mFragmentLayout;
	}
	
	private void initView(){
		mAirPart = (RelativeLayout)mFragmentLayout.findViewById(R.id.airPart);
		mPm25Part = (RelativeLayout)mFragmentLayout.findViewById(R.id.pm25Part);
		mAirFragment = (RelativeLayout)mFragmentLayout.findViewById(R.id.airFragment);
		mPmFragment = (RelativeLayout)mFragmentLayout.findViewById(R.id.pm25Fragment);
		mAirText = (TextView)mFragmentLayout.findViewById(R.id.airText);
		mPmText = (TextView)mFragmentLayout.findViewById(R.id.pmText);
		
	}

	private void initListener()
	{
		mAirPart.setOnClickListener(this);
		mPm25Part.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.airPart:
			changeUI(R.id.airPart);
			break;
		case R.id.pm25Part:
			changeUI(R.id.pm25Part);
			break;
		default:
			break;
		}
	}
	
	private void changeUI(int id){
		if(id == R.id.airPart){
			mAirPart.setBackgroundResource(R.drawable.left_pressed);
			mPm25Part.setBackgroundResource(R.drawable.right_normal);
			mAirFragment.setVisibility(View.VISIBLE);
			mPmFragment.setVisibility(View.GONE);
			mAirText.setTextColor(getActivity().getResources().getColor(R.color.white));
			mPmText.setTextColor(getActivity().getResources().getColor(R.color.titletextcolor));
		}else{
			mAirPart.setBackgroundResource(R.drawable.left_normal);
			mPm25Part.setBackgroundResource(R.drawable.right_pressed);
			mAirFragment.setVisibility(View.GONE);
			mPmFragment.setVisibility(View.VISIBLE);
			mAirText.setTextColor(getActivity().getResources().getColor(R.color.titletextcolor));
			mPmText.setTextColor(getActivity().getResources().getColor(R.color.white));
		}
	}
	
}
